Skip to content

Update docstrings and log messages#7709

Merged
fabaff merged 1 commit into
home-assistant:devfrom
fabaff:render-telegram
May 30, 2017
Merged

Update docstrings and log messages#7709
fabaff merged 1 commit into
home-assistant:devfrom
fabaff:render-telegram

Conversation

@fabaff
Copy link
Copy Markdown
Member

@fabaff fabaff commented May 22, 2017

Description:

Modify rendering of attributes (see comment by @azogue).

Related issue (if applicable): fixes #7705, fixes #7703

Example entry for configuration.yaml (if applicable):

telegram_bot:
  platform: polling
  api_key: !secret telegram_api
  allowed_chat_ids:
    - !secret telegram_client

notify:
  - platform: telegram
    name: telegram
    chat_id: !secret telegram_client

Content for "Service Data" to use in "Call Service". For #7705:

{
  "title": "Test images",
  "message": "The sun is {% if is_state('sun.sun', 'above_horizon') %}up{% else %}down{% endif %}!",
  "data": {
    "photo": {
      "url": "https://home-assistant.io/images/supported_brands/influxdb.png"
    }
  }
}

For #7703:

{
  "title": "Test location",
  "message": "The sun is {% if is_state('sun.sun', 'above_horizon') %}up{% else %}down{% endif %}!",
  "data": {
    "location": {
      "latitude": 32.87336,
      "longitude": 117.22743
    }
  }
}

Checklist:

If the code communicates with devices, web services, or third-party tools:

  • Local tests with tox run successfully. Your PR cannot be merged unless tests pass

Copy link
Copy Markdown
Member

@azogue azogue left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@fabaff, I don't know if you have seen that:

In _get_message_data lies a KeyError when receiving callback queries (introduced in #7689). The chat info is not present there.

You could change it to something like:

if msg_data['from'].get('id') not in self.allowed_chat_ids \
        or ('chat' in msg_data
            and msg_data['chat'].get('id')
            not in self.allowed_chat_ids):
    # Origin is not allowed.
    _LOGGER.error("Incoming message is not allowed (%s)", msg_data)
    return True, None

data = {
    ATTR_USER_ID: msg_data['from']['id'],
    ATTR_FROM_FIRST: msg_data['from']['first_name'],
    ATTR_FROM_LAST: msg_data['from']['last_name']
}
if 'chat' in msg_data:
    data[ATTR_CHAT_ID] = msg_data['chat']['id']

return True, data

Or, if wanted, I could do another PR...

@azogue
Copy link
Copy Markdown
Member

azogue commented May 26, 2017

@fabaff, since you did not answer, and there are more problems in that module, I thought it convenient to open a new PR (#7771). I was waiting for the merge of this, but since it is taking quite a while...

Is that okay?

@MartinHjelmare
Copy link
Copy Markdown
Member

@fabaff I've merged #7771, so if you can rebase this, we can still make use of your doc string clean up. The template issue should already be fixed in #7771 though.

@fabaff fabaff changed the title Modify rendering of attributes (fixes #7705) Update docstrings and log messages May 26, 2017
@fabaff
Copy link
Copy Markdown
Member Author

fabaff commented May 26, 2017

Thanks guys

@fabaff fabaff reopened this May 30, 2017
@fabaff fabaff merged commit 0ccaf97 into home-assistant:dev May 30, 2017
@fabaff fabaff deleted the render-telegram branch May 30, 2017 09:52
@balloob balloob mentioned this pull request Jun 2, 2017
@home-assistant home-assistant locked and limited conversation to collaborators Sep 4, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cannot send any image with telegram after Upgrade to 0.45.0 Location information not being sent to Telegram

5 participants